package com.coolwen.service;

import com.coolwen.dao.UserTeamMapper;
import com.coolwen.entity.SccocerException;
import com.coolwen.entity.UserTeam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created by user on 2016-12-6.
 * 登录用户球员和球队对应信息实现类
 */
@Service("useTeamrService")
public class UserTeamServiceImpl implements UserTeamService {

    @Autowired
    UserTeamMapper userTeamMapper;

    @Override
    public int addUserTeam(UserTeam userTeam) {
    /*判断用户是否拥有球队，如果拥有将不会再去添加球队*/
        if (userTeamMapper.selectByPrimaryKey(userTeam.getUserId()) != null)
            throw new SccocerException("你的队伍已经添加，不能再次添加队伍！");
        return userTeamMapper.insertSelective(userTeam);
    }

    //通过用户的Id查找team
    @Override
    public UserTeam findUserTeamByUserID(Integer userID) {
        return userTeamMapper.selectUserTeamByUserID(userID);
    }
}
